<template>
	<view style="background-color: #f7f6fc;">
        <view class="tou">
            <view class="head" >
		    计划
		</view>
        
        <view class="nav" >
		    <view class="ongoing" @tap="jump(0)">
		       <text :class="[tap?'going-hover':'going']" >进行中{{goingnum}}</text> 
		    </view>
                <view class="past"  @tap="jump(1)" >
                   <text class="going"  :class="[tap?'going':'going-hover']"  >往期的{{pastnum}}</text> 
                </view>
            </view>
        
        </view>
		
		<view class="main" style="margin-top: 260upx;">
		       <past :class="[tap?'pastshow':'']"  :past="past" @reachpast="reachpast"></past> 
               <ongoing :class="[tap?'':'ongoingshow']" :ongoing="ongoing"  @reachgoing="reachgoing"></ongoing>
		</view>
	
	</view>
</template>

<script>
    import past from "../../component/past/past.vue"
      import ongoing from "../../component/ongoing/ongoing.vue"
  import {WebSocket} from '../../js/websocket-uni.js'
  import {Stomp} from '../../js/stomp.min.js'
	export default {
        components: {
            past,
           ongoing
        },
    
		data() {
			return {
				switch:1,
                tap:true,
                ongoing:0,
                past:0,
                goingnum:0,
                pastnum:0,
                backNum:1
			}
		},
		onNavigationBarButtonTap() {
			const subNVue = uni.getSubNVueById("nav");
			console.log(subNVue)
			subNVue.show("zoom-fade-out", 100, function(){  
});  
		},
		methods: {
			jump(num){     
                let tap = this.tap;
                
                if(tap == true && num == 0){
                    return
                }
                if( tap == false && num == 1){
                    return
                }      
                this.tap = !tap;
            },
            reachgoing(){
                this.ongoing = 0;
            },
            reachpast(){
                this.past = 0;
            }
		},
		  //  onLoad: function (options) {
    //     setTimeout(function () {
    //         console.log('start pulldown');
    //     }, 1000);
    //     uni.startPullDownRefresh();
    // },
    // onPullDownRefresh() {
    //     console.log('refresh');
    //     setTimeout(function () {
    //         uni.stopPullDownRefresh();
    //     }, 1000);
    // }
    onReachBottom() {
        
        
        
        if(this.tap == false)
        {
           
            this.past = 1;
        }
        if(this.tap == true){
            this.ongoing = 1;
             console.log("刷到底了")
            
        }
        
    },
    onLoad() {
        let c = this;
        
          
           
           uni.getStorage({
               key:"ongoingfirst",
               success(res) {
                    c.goingnum  = res.data.planNum;
           c.pastnum = res.data.formerlyPlanNum;
               }
           })
           
           
           // var backNum = 1;
                
           //      plus.key.addEventListener("backbutton",function(){
                    
           //          if(backNum == 1){
                        
           //              let userInfos = uni.getStorageSync("userInfos");
                               
           //                     let {userId,token} = userInfos  
           //                      console.log(userId);
                                 
                                  
           //                    var url = "wss://47.103.64.35:8996/websocket"
                         
           //               //       var socket = new SockJS(url);
           //                     var  stompClient = Stomp.client(url);
                               
           //                     console.log(stompClient);
                             
                         
                   
           //              let connect = uni.getStorageSync("hasconnect");
           //                console.log(connect);
                        
           //              //断开连接的方法
           //              if (stompClient !== undefined && connect =="done") {
                              
                        
                            
           //                  var headers ={
           //                      userId:userId
           //                  }
                                     
           //                  stompClient.disconnect(headers,function(){
           //                      console.log("发送成功");
           //                       uni.removeStorageSync("hasconnect");
           //                  });
                            
           //                  console.log("Disconnected");
           //              }else{
           //                  console.log("当前没有连接websocket")
           //              }
                        
                        
           //            plus.nativeUI.toast('再次按下返回键退出');
           //                 backNum++;
           //          }
                    
                    
           //        if(backNum == 2){
                                         
           //               setTimeout(function(){
                       
           //                   plus.runtime.quit();
              
           //          },1500)                  
           // }
                  
                    
                    
           //      });
     
    },
    onShow() {
        
        let c = this;
           uni.$emit('updatelo',{msg:'页面更新'});
           
           uni.$on('again',function(data){
          c.goingnum ++;     
               
         uni.$emit('updatelo',{msg:'页面更新'});
        
      
        
    })
           
    
    },
 onBackPress(){
            
            let c =this;
            
            if(c.backNum == 1){
                  
                  let userInfos = uni.getStorageSync("userInfos");
                         
                         let {userId,token} = userInfos  
                          console.log(userId);
                           
                            
                        var url = "wss://47.103.64.35:8996/websocket"
                   
                   //       var socket = new SockJS(url);
                         var  stompClient = Stomp.client(url);
                         
                         console.log(stompClient);
                       
                   
             
                  let connect = uni.getStorageSync("hasconnect");
                    console.log(connect);
                   uni.removeStorageSync("hasconnect");
                  //断开连接的方法
                  if (stompClient !== undefined && connect =="done") {
                        
                  
                      
                      var headers ={
                          userId:userId
                      }
                               
                      stompClient.disconnect(headers,function(){
                          console.log("发送成功");
                          
                      });
                      
                      console.log("Disconnected");
                  }else{
                      console.log("当前没有连接websocket")
                  }
                  
                  
                plus.nativeUI.toast('再次按下返回键退出');
                     c.backNum++;
              }
              
              
            if(c.backNum == 2){
                                   
                   setTimeout(function(){
                 
                       plus.runtime.quit();
                           
              },1500)  
                }
            
            
            
            }
	}
</script>

<style>
   .swiper{
	   margin-top: 20upx;
   }
   .view{
	font-size:28upx; 
	line-height:1.8;
	margin-top: 30upx;
	background-color: #808080;
	border-radius: 6upx;
   }
  .text{
	  display: flex;
	  justify-content:center;
	  color: #EEEEEE;
	  font-size: 40upx;
	  font-weight: 800;
	  
  }
 .button{
	 color: #EEEEEE;
	 margin: 30upx;
	 border-radius: 30upx;
	 }
  .button-hover{
	background: #0A98D5;
  }
  .head{
      padding-top: 80upx;
      text-align: center;
      font-size: 40upx;
      font-weight: 800;
      color: #333333;
      background-color: #FBFBFB;
      width: 750upx;   
  }
  .nav{
      padding-top: 5upx;
      display: flex;
      flex-direction: row;
      background-color:#FBFBFB ;
      padding-bottom: 20upx;
       width: 750upx;
  }
  .ongoing{
      width: 50%;
     text-align: center;
  }
  .past{
      width: 50%;
      text-align: center;
  }
  .going{
      width:300upx;
      color: #333333;
      font-size: 35upx;
      font-weight: 800;
      padding-left: 30upx;
      padding-right: 30upx;
  }
  .going-hover{
     width:260upx;
     color: #333333;
     font-size: 35upx;
     font-weight: 800;
     padding-bottom: 10upx;
     border-bottom: 2px solid #FAC266;  
     padding-left: 30upx;
     padding-right: 30upx;
  }
  .tou{
      position: fixed;
      width: 750upx;
      height: 250upx;
      top: 0px;
       z-index:2009;
  }
  .ongoingshow{
      display: none;
  }
  .pastshow{
      display: none;
  }
</style>
